using Microsoft.AspNetCore.Authorization;

using WXWorkSvc.Common.Extensions;
using WXWorkSvc.Common.Models;
namespace WXWorkSvc.Third.Areas.D.Pages.User;

public class UserInfoModel : PageModel
{
    private readonly WXDbContext db;
    public TUser Item { get; set; } = default!;
    public UserInfoModel(WXDbContext dbc)
    {
        db = dbc;
    }
    public async Task OnGetAsync([FromServices] WXWork3rdConfig config, [FromServices] IRole r)
    {
        var admin = r.Admin;
        Item = await db.Users.Where(ii => ii.SuiteId == config.SuiteId && ii.CorpId == User.GetCorpId() && ii.UserId == User.Identity!.Name).FirstAsync();
        Item.RoleNames = r.GetRoleNames(Item.Roles);

        Item.Admins = string.Join(" | ", await db.Users.Where(ii => ii.SuiteId == config.SuiteId && ii.CorpId == User.GetCorpId() && (ii.Roles & admin) > 0).Select(ii => ii.UserName).ToListAsync());
    }


}
